package com.qisi.kandroidshalon.delegate

import android.util.Log
import kotlin.reflect.KProperty

/**
 * 自定义委托类，自定义委托类需要实现属性委托的接口，即具备 getValue 和 setValue 方法，别的对象才能委托属性给它
 */
class CustomDelegate {
    private val TAG = "CustomDelegate"
    private var value: String = ""

    public val lazyVal:String by lazy {
        Log.i(TAG, "lazy init")
        "hello i am lazy init"
    }

    operator fun getValue(thisRef: Any?, property: KProperty<*>): String {
        Log.i(TAG, "Getting value: $value")
        return value
    }

    operator fun setValue(thisRef: Any?, property: KProperty<*>, newValue: String) {
        Log.i(TAG, "Setting value: $newValue")
        value = newValue
    }

}